/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: AbstractValidateCodeProcessor
 * Author:   zhouheng
 * Date:     2019/6/11 21:15
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.security.code;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.ServletWebRequest;

import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author zhouheng
 * @create 2019/6/11
 * @since 1.0.0
 */
public abstract class AbstractValidateCodeProcessor<C extends ValidateCode> implements ValidateCodeProcessor {

    Map<String,ValidateCodeGenerator> validateCodeGenerators;

//    public AbstractValidateCodeProcessor() {
//        validateCodeGenerators.put(getValidateCodeType().toString().toLowerCase(),null);
//    }

    @Override
    public void create(ServletWebRequest request) {
        C valicode = generate(request);
        save();
        send();
    }

    /**
     * @description: 发送验证码 由子类实现
     * @date: 2019/6/11 22:29
     * @author:zhouheng
     */
    protected abstract void send();

    /**
     * @description: 保存校验码
     * @date: 2019/6/11 21:17
     * @author:zhouheng
     */
    protected void save(){

    }

    /**
     * @description: 生成校验码
     * @date: 2019/6/11 21:16
     * @author:zhouheng
     */
    public C generate(ServletWebRequest request){
        String type = getValidateCodeType().toString().toLowerCase();

        return null;
    }

    public abstract ValidateCodeType getValidateCodeType(); /* {
        String type = StringUtils.substringBefore(getClass().getSimpleName(), "CodeProcessor");
        return ValidateCodeType.valueOf(type.toUpperCase());
    }*/

    @Override
    public void validate(ServletWebRequest request) {

    }
}